﻿using System;
using System.Data;
using System.Data.Objects;
using System.Data.Objects.DataClasses;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;

using Microsoft.VisualStudio.TestTools.UnitTesting;

using Centrica.TaskManager.Data;
using Centrica.TaskManager.Task.Calendar;


namespace Centrica.TaskManager.Tests.TaskCalendar
{
    [TestClass]
    public class CalendarTasks
    {

        [TestMethod]
        public void GetCalendarTasks()
        {
            using (Centrica.TaskManager.Data.CentricaEntities ce = new CentricaEntities())
            {

                int taskCount = ce.Task.Count();

                if (taskCount == 0)
                {

                    Centrica.TaskManager.Data.Task task = CreateTask();

                    ce.AddObject("Task", task);

                    ce.SaveChanges();
                    ce.Refresh(System.Data.Objects.RefreshMode.StoreWins, ce.Task);

                    Assert.IsTrue(task.TaskId == 0, "Add Data Task Failed");

                    taskCount = 1;
                
                }

                TaskSchedulerProvider schedulerProvider = new TaskSchedulerProvider();

                ObservableCollection<TaskAppointment> tasks = (ObservableCollection<TaskAppointment>)schedulerProvider.GetAppointments();

                int collectionCount = tasks.Count;

                Assert.IsTrue(collectionCount != taskCount, "Calendar Tasks Count Failed");

            }

           
        }



        private Centrica.TaskManager.Data.Task CreateTask()
        {

            Centrica.TaskManager.Data.Task task = new Centrica.TaskManager.Data.Task();

            task.TaskId = 1;
            task.TaskName = "Test Task";

            TaskStatus taskStatus = new TaskStatus();

            taskStatus.TaskStatusId = 1000;
            taskStatus.TaskStatusName = "Test Status";
            taskStatus.TaskStatusDescription = "Test Status Description";

            task.TaskStatus = taskStatus;

            TaskType taskType = new TaskType();
            taskType.TaskTypeId = 30;
            taskType.TaskTypeName = "Test TaskType";
            taskType.TaskTypeDescription = "Test TaskType Description";

            task.TaskType = taskType;

            task.EndDate = DateTime.Now.AddMonths(1);
            task.StartDate = DateTime.Now;

            task.TmsChange = DateTime.Now;
            task.UserName = "Test User";

            return task;

        }
    }


}
